Supercharge Your Flow

Tips and Tricks for improving RStudio IDE Development Efficiency

Mayank Agrawal
Senior R developer Consultant I
ProCogia

Tuesday, August 1, 2023

Hello, There

This presentation will show you examples of what you can do with RStudio IDE, including:

  • RStudio Projects
  • Personalizing your IDE
  • Navigating Views
  • Keyboard Shortcuts for different development flows
    • Searching variables in a broader context
    • Code Beautification Options
    • Code Folding and Run Options
    • Code Comments Outline Setup
    • History of previous commands used
    • …and much more

RStudio Projects

RStudio projects make it straightforward to divide your work into multiple contexts, each with their own working directory, workspace, history, and source documents.

Why should I use it?

  • Isolates your development environment.

  • Relative path referencing for your project files.

  • Helps setup project package management via renv or packrat

  • Segregate development flow and context.

How to create a new RStudio Project?

Use your RStudio IDE Toolbar:

  • File –> New Project –> (Choose) New Directory/Existing Directory/Version Control

Personalize your RStudio IDE

Options

The available options for the RStudio IDE are accessible from the Options dialog - Tools > Global Options menu.

  • General R Options — Default CRAN mirror, initial working directory, workspace and history behavior.
  • Source Code Editing — Enable/disable line numbers, selected word and line highlighting, soft-wrapping for R files, paren matching, right margin display, and console syntax highlighting; configure tab spacing; set default text encoding.
  • Appearance and Themes — Specify font size and visual theme for the console and source editor.
  • Pane Layout — Locations of console, source editor, and tab panes; set which tabs are included in each pane.
  • Packages — Set default CRAN repository and specify package development options.
  • Spelling — Choose main dictionary language and specify spell checking options.
  • Git/SVN — Configure locations of Git and Svn binaries and create and/or view SSH RSA keys.
  • Publishing — Enable publishing apps and documents from IDE. Set account.

Single Pane View

If you prefer to only have one pane in view at a time, add Shift to any of the previous commands to maximize the pane. Use the following shortcuts to bring a panes into primary focus seamlessly (Mac/Windows):

  • Control/Ctrl + Shift + 1: Source editor (your script) pane only

  • Control/Ctrl + Shift + 2: Console pane only

  • Control/Ctrl + Shift + 3: Help pane only

  • Control/Ctrl + Shift + 4: History pane only

  • Control/Ctrl + Shift + 5: Files pane only

  • Control/Ctrl + Shift + 6: Plots pane only

  • Control/Ctrl + Shift + 7: Packages pane only

  • Control/Ctrl + Shift + 8: Environment pane only

  • Control/Ctrl + Shift + 9: Viewer pane only

The Classic Four Pane View

Wait! How do I go back to the classic four-pane view?

Control/Ctrl + Shift + 0 (Mac/Windows): Four-pane RStudio IDE View

Keyboard Shortcuts

RStudio provides dozens of useful shortcuts that you can access through the menu at the top:

Tools > Keyboard Shortcuts Help.

Console

Description Windows & Linux Mac
Shift focus of cursor to Console Ctrl + 2 Control + 2
Clear Console Ctrl + L Control + L
Move Cursor to beginning of a line Home Cmd + Left
Move Cursor to end of a line End Cmd + Right
Move Cursor to start/end of a word Alt + Left/Rigth Option + Left/Right
Navigate command history Up/Down Up/Down
Pop-up Command history Ctrl + Up Cmd + Up

Source Scripts

Description Windows & Linux Mac
Toggle document outline Ctrl + Shift + O Cmd + Shift + O
Clear Console Ctrl + L Control + L
New R Script Ctrl + Shift + N Cmd + Shift + N
Save active document Ctrl + S Cmd + S
Save all documents Ctrl + Alt + S Cmd + Option + S
Close active document Ctrl + W Cmd + W
Close all open documents Ctrl + Shift + W Cmd + Shift + W
Knit and Preview Document (knitr) Ctrl + Shift + K Cmd + Shift + K
Insert Chunk Ctrl + Alt + I Cmd + Option + I

Find

Description Windows & Linux Mac
Find and Replace Ctrl + F Cmd + F
Find in Files Ctrl + Shift + F Cmd + Shift + F

Insert

Description Windows & Linux Mac
Insert Assignment Operator (<-) Alt + - (hyphen/minus) Option + - (hyphen/minus)
Insert Pipe Operator (%>%) Ctrl + Shift + M Cmd + Shift + M

Code

Description Windows & Linux Mac
Re-indent lines Ctrl + I Cmd + I
Comment/un-comment current line/selection Ctrl + Shift + C Cmd + Shift + C
Reformat Selection Ctrl + Shift + A Cmd + Shift + A
Move Lines Up/Down Alt + Up/Down Option + Up/Down
Copy Lines Up/Down Shift + Alt + Up/Down Cmd + Option + Up/Down
Jump to Matching Brace/Parenthesis Ctrl + P Control + P
Add Cursor Above/Below Current Cursor Ctrl + Alt + Up/Down Control + Option + Up/Down
(Alternate) Add Cursor via drag Alt + drag mouse pointer Option + drag mouse pointer
Delete Current Line Ctrl + D Cmd + D
Insert Roxygen Skeleton Ctrl + Alt + Shift + R Cmd + Option + Shift + R
Attempt Code Completion Tab or Ctrl + Space Tab or Cmd + Space

Code Sections

Description Windows & Linux Mac
Run current line/selection Ctrl + Enter Cmd + Return
Run current document Ctrl + Alt + R Cmd + Option + R
Send current line/selection to terminal Ctrl + Alt + Enter Cmd + Option + Return
Fold Selected Alt + L Cmd +``Option + L
Unfold Selected Shift + Alt + L Cmd + Shift + Option + L
Fold All Alt + O Cmd + Option + O
Unfold All Shift + Alt + O Cmd + Shift + Option + O

Tabs

Description Windows & Linux Mac
Switch to tab Ctrl + Shift +. [period] Control + Shift + . [period]
Next tab (desktop) Ctrl + Tab Control + Tab
Previous tab (desktop) Ctrl + Shift + Tab Control + Shift + Tab
(Alternate) Shift between tabs left/right Ctrl + Alt + left/right Control + Option + left/right
Next tab (Workbench) Ctrl + F12 Control + F12
Previous tab (Workbench) Ctrl + F11 Control + F11

Terminal

Description Windows & Linux Mac
Move Focus to Terminal Alt + Shift + M Shift + Option + M
New Terminal Alt + Shift + R Shift + Option + R

Session

Description Windows & Linux Mac
Restart R session Ctrl + Shift + 0 Cmd + Shift + 0

References

References - RStudio IDE

  • RStudio Shortcuts Cheat sheet:

    • RStudio IDE Toolbar: Help –> Keyboard Shortcuts Help

    • Mac: Option + Shift + K

    • Windows: Alt + Shift + K

  • Customizing the RStudio IDE: Link 1 Link 2

  • 23 RStudio Tips, Tricks, and Shortcuts by DataQuest Link

  • Comprehensive documentation and self help guides for using RStudio IDE Link

  • Using RStudio Projects. Link

References - Shiny and Quarto